//
//  ViewController.swift
//  SafeAreaInsetsDemo3
//
//  Created by 李煜 on 2024/6/6.
//https://blog.csdn.net/u013712343/article/details/107211700/

import UIKit

class ViewController: UIViewController {
    
    lazy var yellowView: UIView  = {
        let y = UIView()
        y.backgroundColor = .yellow
        view.addSubview(y)
        return y
    }()
    lazy var blueView: UIView  = {
        let y = UIView()
        y.backgroundColor = .blue
        yellowView.addSubview(y)
        return y
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .red
    }
    override func viewSafeAreaInsetsDidChange() {
        super.viewSafeAreaInsetsDidChange()
        
        if #available(iOS 11.0, *) {
            self.additionalSafeAreaInsets = UIEdgeInsets.init(
                top: 50,
                left: 50,
                bottom: 50,
                right: 50
            )
        } else {
            // Fallback on earlier versions
        }
        yellowView.snp.makeConstraints { (make) in
            make.edges.equalTo(UIEdgeInsets.zero)
//            make.edges.equalTo(view.safeAreaLayoutGuide)
        }
        
        blueView.snp.makeConstraints { (make) in
            if #available(iOS 9.0, *) {
                make.edges.equalTo(self.yellowView.layoutMarginsGuide)
            } else {
                // Fallback on earlier versions
            }
        }
        
        print(view.safeAreaInsets)
        print("safearea:\n",yellowView.safeAreaInsets,"\nmargin:\n",yellowView.layoutMargins)
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        print("blue: \(blueView.frame)")

    }
}

